#! /usr/bin/env python

import pycurl

class GetPage:
	def __init__ (self, url, ua):
		self.contents = ''
		self.url = url
		self.ua = ua
		self.curl = pycurl.Curl()
		self.curl.setopt(self.curl.URL			,url)
		self.curl.setopt(self.curl.USERAGENT		,ua)
		self.curl.setopt(self.curl.FOLLOWLOCATION	,10)
		self.curl.setopt(self.curl.MAXREDIRS		,1)
		self.curl.setopt(self.curl.WRITEFUNCTION	,self.read_page)

	def DownloadPage (self):
		try:
			self.curl.perform()
		except:
			pass
		return self.contents

	def read_page (self, buf):
		self.contents = self.contents + buf

	#def show_page (self):
	#	print self.contents

	def Reset (self, url):
		self.contents = ''
		self.url = url
		self.curl.setopt(self.curl.URL			,url)

	def Close (self):
		self.curl.close()
